import axios from "axios";
// 请求时候的滚动条
import NProgress from 'nprogress'

axios.defaults.baseURL = `https://superzhen.kafuuchino.com.cn/api/private/v1/`

axios.defaults.timeout = 5000

axios.interceptors.request.use(function(config) {
    // 显示滚动条
    NProgress.start();
    let userinfo = localStorage.getItem('userinfo')
    if (userinfo) {
        userinfo = JSON.parse(userinfo)
        config.headers['Authorization'] = userinfo.token
    }
    return config;
}, function(error) {
    return Promise.reject(error)
})

axios.interceptors.response.use(function(response) {
    setTimeout(() => {
        // 结束请求滚动条
        NProgress.done();
    }, 1000);
    return response.data;
}, function(error) {
    return Promise.reject(error)
});

export default axios